package com.tanhua.server.controller;

/**
 * @ClassName LoginController
 * @Description TODO
 * @Author @O_o
 * @Date 2023/10/28 12:55
 * @Version 1.0
 */


import com.tanhua.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class LoginController {

    @Autowired
    private UserService userService;

    /**
     * 用户登录-发送验证码
     */
    @PostMapping("/login")
    public ResponseEntity login(@RequestBody Map map) {
        //1、获取手机号码
        String mobile = (String) map.get("phone");
        //2、调用service发送短信
        return userService.sendMsg(mobile);
    }

    /**
     * 验证码校验登录
     */
    @PostMapping("/loginVerification")
    public ResponseEntity loginVerification(@RequestBody Map map) {
        //1、调用map集合获取请求参数
        String phone = (String) map.get("phone");
        String code = (String) map.get("verificationCode");
        //2、调用userService完成用户登录
        Map retMap = userService.loginVerification(phone,code);
        //3、构造返回
        return ResponseEntity.ok(retMap);
    }
}

